package com.example.yuanann.vegetable_app.fragment;

import static android.content.Context.MODE_PRIVATE;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.yuanann.vegetable_app.MainApplication;
import com.example.yuanann.vegetable_app.R;
import com.example.yuanann.vegetable_app.activity.Home;
import com.example.yuanann.vegetable_app.activity.Login;
import com.example.yuanann.vegetable_app.activity.Order;
import com.example.yuanann.vegetable_app.activity.Register;


public class Merchant extends Fragment {

    private TextView shopCart, loginOutView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.activity_mine,container,false);
        return view;
    }
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);
        super.onCreate(savedInstanceState);

        shopCart = (TextView)getActivity().findViewById(R.id.shopCart);

        loginOutView = (TextView)getActivity().findViewById(R.id.zx);

        TextView myyhq=(TextView)getActivity().findViewById(R.id.myyhq);
        TextView myjf=(TextView)getActivity().findViewById(R.id.myjf);
        TextView a1=(TextView)getActivity().findViewById(R.id.a1);
        TextView a2=(TextView)getActivity().findViewById(R.id.a2);
        TextView a3=(TextView)getActivity().findViewById(R.id.a3);
        TextView a4=(TextView)getActivity().findViewById(R.id.a4);
        TextView a5=(TextView)getActivity().findViewById(R.id.a5);
        TextView name=(TextView) getActivity().findViewById(R.id.name);
        SharedPreferences sp =  getActivity().getSharedPreferences("name", MODE_PRIVATE);
        String b = "欢迎您，"+sp.getString("name", null);
        name.setText(b);
        SharedPreferences sp1 =  getActivity().getSharedPreferences("allyhq", MODE_PRIVATE);
        int num =sp1.getInt("yhq", 0);
        String yhqnum=num+"";
        myyhq.setText(yhqnum);

       a2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), Order.class);
                startActivity(intent);
            }
        });
       shopCart.setOnClickListener( (view) -> {
           //实例化fragment
           Fragment four=new Goodss();
           //实例化管理器
           FragmentManager fm = getFragmentManager();;
           //定义事务
           FragmentTransaction ft=fm.beginTransaction();
           //将当前的fragment替换为第二个
           ft.replace(R.id.fag1,four);
           //提交事务
           ft.commit();
       });

       loginOutView.setOnClickListener( (view) -> {
           Intent intent = new Intent();
           intent.setClass(MainApplication.getContext(), Login.class);
           startActivity(intent);
       });

    }
}

